package com.jt.aop;

import com.jt.pojo.User;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Aspect
@Component
public class ServiceAop {
    @Pointcut("within(com.jt.service.UserServiceImpl)")
    public void service() {

    }

    static Map<Integer, User> map = null;

    @Around("service()")
    public void around(ProceedingJoinPoint joinPoint) {
        if (map == null) {
            map = new HashMap();
            try {

                map.put(1, (User) joinPoint.getArgs()[0]);
            } catch (Throwable t) {
                t.printStackTrace();
            }
        }
        System.out.println(map.get(1) + "缓存数据");
        ;

    }
}
